<template>
  <div class="loginConent">
    <div class="loginFrom">
      <el-row class="logoBox">
        <el-col :span="24">
          <img class="logoImg" src="@/assets/logo.png" alt="">
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form ref="loginRef" :model="loginFrom">
            <el-form-item prop="id" class="iptOne">
              <span class="elementBox">
                <img src="@/assets/phone.png">
              </span>
              <el-input v-model.trim="loginFrom.id" type="text" />
            </el-form-item>
            <el-form-item prop="pwd" class="iptTow">
              <span class="elementBox">
                <img src="@/assets/pwd.png">
              </span>
              <el-input v-model.trim="loginFrom.pwd" :type="passwordType" />
              <span class="show-pwd" @click="showPwd">
                <svg-icon
                  :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
                />
              </span>
            </el-form-item>
            <el-form-item prop="submitInfo" class="iptThree">
              <el-checkbox label="记住密码" name="type" />
            </el-form-item>
            <el-form-item prop="submitInfo" class="ipyFour">
              <el-button :loading="loading" @click="loginFn"><b>立即登陆</b></el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </div>
    <div class="loginImg">
      <img src="../../assets//contentBg.png">
    </div>
  </div>
</template>

<script>
import { setToken } from '@/utils/auth'
export default {
  data() {
    return {
      loading: false,
      token: 'eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJiNTJlYWUxMS0yYWZiLTQwYjUtODg3NC01OTEwOGU0YjI0NjUiLCJzdWIiOiJ7XCJyb2xlXCI6XCJST0xFX0FETUlOXCIsXCJ0eXBlXCI6XCIyXCIsXCJ1c2VybmFtZVwiOlwiYWRtaW5cIn0iLCJpc3MiOiJhZG1pbiIsImlhdCI6MTYwNjM3MTA3NiwiZXhwIjoxNjA2OTc1ODc2fQ.pCl45pY_v2w8rZU8l60UI4cQx-Ufl7DRw0rZqhY8zeE',
      // 小眼睛状态
      passwordType: 'password',
      // 登陆表单
      loginFrom: {
        id: 'admin',
        pwd: 'admin',
        submitInfo: false
      }
    }
  },
  methods: {
    // 密码框小眼睛
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    // 登陆逻辑
    loginFn() {
      this.loading = true
      this.$refs.loginRef.validate(valid => {
        if (!valid) return
        // 登陆后台
        this.$store.state.user.token = setToken(this.token)
        this.$router.push('/')
      })
      this.loading = false
    }
  }
}
</script>

<style lang="scss" scoped>
$dark_gray: #889aa4;
.loginConent{
  box-sizing: border-box;
  width: 958px;
  height: 516px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  box-shadow: 0 0 20px rgb(93 93 93 / 33%);
  background-color:#fff;
  border-radius: 40px;
  display: flex;
  overflow: hidden;
  .loginFrom{
    width: 398px;
    height: 100%;
    .logoBox{
      .logoImg{
      width: 150px;
      margin-left: 124px;
      margin-top: 72px;
    }
    }
    .el-form-item{
      width: 280px;
      height: 50px;
      margin-left: 50%;
      transform: translateX(-50%);
    }
    .iptOne{
      margin-top: 50px;
    }
    .iptTow{
      margin-top: 43px;
    }
    .iptThree{
      margin-top: -15px;
    }
    .ipyFour{
      margin-top: -14px;
      border-radius: 8px;
    }
    .el-button{
      width: 100%;
      height: 50px;
      background-color: #f4b53f;
      color: #000;
      font-size: 16px;
      box-shadow: 0 0 8px #ccc;
      border: 0 solid #fff;
    }
  }
  .loginImg{
    width: 560px;
    height: 100%;
    img{
      margin-top: -2px;
      width: 561px;
      height: 519px;
    }
  }
}

::v-deep .el-form-item__content{
  display: flex;
  line-height: 50px;
  .elementBox{
    width: 62px;
    background-color: #e9e7e7 !important;
    position: relative;
    border-radius: 8px 0 0 8px;
    font-size: 14px;
    img{
      width: 24px;
      height: 25px;
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      margin: auto;
    }
  }
}
::v-deep .el-input__inner{
  height: 50px;
  width: 230px;
  border-radius:0 8px  8px 0;
  background-color: #f7f5f5;
  border: 1px solid #f7f5f5;
  color: #000;
  &:hover{
    border: 1px solid #000;
  }
}
.show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }
</style>
